import json

# 加载 JSON 文件
def load_json(file_path):
    with open(file_path, "r", encoding="utf-8") as f:
        return json.load(f)

# 统计并打印结果
def analyze_data(data):
    # 初始化统计变量
    correct_count_paris = 0
    total_count_paris = 0
    incorrect_paris = []

    correct_count_christianity = 0
    total_count_christianity = 0
    incorrect_christianity = []

    correct_count_yes = 0
    total_count_yes = 0
    incorrect_yes = []

    correct_count_no = 0
    total_count_no = 0
    incorrect_no = []

    # 遍历数据
    for item in data:
        id = item["id"]
        label = item["label"]
        answer = item["answer"]

        # 忽略 id=10, 20, 30,40
        if id in [10, 20, 30,40]:
            continue

        # 对 id=1~9 检查 answer 是否为 Paris
        if 1 <= id <= 9:
            total_count_paris += 1
            if answer == "Paris":
                correct_count_paris += 1
            else:
                incorrect_paris.append({"id": id, "label": label})

        # 对 id=11~19 检查 answer 是否为 Christianity
        if 11 <= id <= 19:
            total_count_christianity += 1
            if answer == "Christianity":
                correct_count_christianity += 1
            else:
                incorrect_christianity.append({"id": id, "label": label})

        # 对 id=21~29 检查 answer 是否为 Yes
        if 21 <= id <= 29:
            total_count_yes += 1
            if answer == "Yes":
                correct_count_yes += 1
            else:
                incorrect_yes.append({"id": id, "label": label})

        # 对 id=31~39 检查 answer 是否为 No
        if 31 <= id <= 39:
            total_count_no += 1
            if answer == "No":
                correct_count_no += 1
            else:
                incorrect_no.append({"id": id, "label": label})

    # 打印统计结果
    print("id=1~9 的统计结果：")
    print(f"正确率: {correct_count_paris / total_count_paris * 100:.2f}%")
    print("不正确的数据项：")
    for item in incorrect_paris:
        print(f"id: {item['id']}, label: {item['label']}")

    print("\nid=11~19 的统计结果（answer是否为Christianity）：")
    print(f"正确率: {correct_count_christianity / total_count_christianity * 100:.2f}%")
    print("不正确的数据项：")
    for item in incorrect_christianity:
        print(f"id: {item['id']}, label: {item['label']}")

    print("\nid=21~29 的统计结果（answer是否为Yes）：")
    print(f"正确率: {correct_count_yes / total_count_yes * 100:.2f}%")
    print("不正确的数据项：")
    for item in incorrect_yes:
        print(f"id: {item['id']}, label: {item['label']}")

    print("\nid=31~39 的统计结果（answer是否为No）：")
    print(f"正确率: {correct_count_no / total_count_no * 100:.2f}%")
    print("不正确的数据项：")
    for item in incorrect_no:
        print(f"id: {item['id']}, label: {item['label']}")

# 主程序
if __name__ == "__main__":
    file_path = "parsed_results.json"  # JSON 文件路径
    data = load_json(file_path)
    analyze_data(data)